//
// Created by Administrator on 2021/5/27.
// @file test_acct.cpp
// @author jmdvirus
// @date 2021-05-27 17:07:48
//

#include "cm_utils.h"
#include <stdio.h>
#include <sys/acct.h>

#define TOLONG(c) ((c & 0x1fff) << (((c >> 13) & 0x7) * 3))

int test_acct(const char *file)
{
    char *data = NULL;
    int   len  = 0;
    cm_read_file_data(file, &data, &len);
    if (data)
    {
        size_t       s  = len / sizeof(struct acct);
        struct acct *at = (struct acct *)data;
        for (int i = 0; i < s; i++)
        {
            printf("index : %d-%lu\n", i, s);
            printf("string : %x, %s\n", at->ac_flag, at->ac_comm);
            printf("cpu %d, mem %d\n", TOLONG(at->ac_utime),
                   TOLONG(at->ac_mem));
            at = (struct acct *)data + (i + 1) * sizeof(struct acct);
        }
    }
    return 0;
}

int main(int argc, char **args)
{
    const char *file = args[1];
    test_acct(file);

    return 0;
}